import React, { Component } from 'react'
import { Route, Routes, Navigate } from "react-router-dom";
import About from "./components/About";
import Home from "./components/Home";
import Header from "./components/Header";
import MyNavLink from "./components/MyNavLink";
// import Test from "./components/Test";

export default class App extends Component {
  render() {
    return (<div>
      <div className="row">
        <div className="col-xs-offset-2 col-xs-8">
          <Header/>
        </div>
      </div>
      <div className="row">
        <div className="col-xs-2 col-xs-offset-2">
          <div className="list-group">
            {/* 原生a标签跳转 */}
            {/* <a className="list-group-item active" href="./about.html">About</a>
            <a className="list-group-item" href="./home.html">Home</a> */}

            {/* 在react中靠路由链接实现切换组件 */}
            {/* <NavLink className={({isActive}) => (isActive? "list-group-item nav":"list-group-item")} to="/about">About</NavLink> */}
            {/* <NavLink className={({isActive}) => (isActive? "list-group-item nav":"list-group-item")} to="/home">Home</NavLink> */}
            <MyNavLink to='/about'>About</MyNavLink>
            <MyNavLink to='/home'>Home</MyNavLink>
          </div>
        </div>
        <div className="col-xs-6">
          <div className="panel">
            <div className="panel-body">
              {/* <h3>?????</h3> */}
              {/* 注册路由 */}
              {/* Routes标签作用为匹配到就终止继续向下匹配,5.0版本需要exact属性开启严格匹配 6.0版本以上默认开启了严格匹配 */}
              <Routes>
                <Route path="about" element={<About />} />
                {/* 6.0版本路由 如果有子路由 需要在父路由后面加  "/*" */}
                <Route path="home/*" element={<Home/>} />
                {/* 6.0版本路由重定向使用Navigate */}
                <Route path="*" element={<Navigate to="/about" />}/> 
              </Routes>
            </div>
          </div>
        </div>
      </div>
    </div>
    )
  }
}